package com.hl.sfzy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.FieldsOfExcellence;
import com.hl.sfzy.service.FieldsOfExcellenceService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/fields")
@CrossOrigin
public class FieldsOfExcellenceController {
    @Autowired
    private FieldsOfExcellenceService fieldsOfExcellenceService;
    @RequestMapping("/selectByConsultant")
    public R selectByConsultant(@RequestParam(required = false ,defaultValue = "1")int pageNum,
                                @RequestParam(required = false,defaultValue = "5") int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<FieldsOfExcellence> info = new PageInfo<>(fieldsOfExcellenceService.selectByConsultant());
        return R.ok(info);
    }
    @RequestMapping("/selectAll")
    public R selectAll(){
        return R.ok(fieldsOfExcellenceService.selectAll());
    }
    @RequestMapping("/insert")
    public R insert(FieldsOfExcellence record){
        return R.ok(fieldsOfExcellenceService.insert(record));
    }
    @RequestMapping("/deleteById")
    public R deleteById(Long id){
        return R.ok(fieldsOfExcellenceService.deleteById(id));
    }
    @RequestMapping("/selectById")
    public R selectById(Long id){
        return R.ok(fieldsOfExcellenceService.selectById(id));
    }
    @RequestMapping("/selectByConsultantId")
    public R selectByConsultantId(int id){
        return R.ok(fieldsOfExcellenceService.selectByConsultantId(id));
    }
}
